<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
			<div>
				<button @click="permissionTest">执行权限</button>
				<button @click="createTest">执行创建测试</button>
				<button @click="searchDevice">执行查找设备</button>
				<button @click="connectDevice">执行连接设备</button>	
				<button @click="isEnableBlueBooth">执行当前蓝牙是否开启</button>	
				<button @click="openWaveFormCallback">打开波形数据上传</button>	
				<button @click="closeWaveFormCallback">关闭波形数据上传</button>	
				<button @click="openListenBloodOxygenParam">打开血氧数据回调</button>	
				<button @click="closeListenBloodOxygenParam">关闭血氧数据回调</button>	
				
				<button @click="searchFxDevice">查找复吸设备</button>	
				<button @click="connectFxDevice">连接复吸设备</button>	
			</div>
		</view>
	</view>
</template>

<script>
	const bloodModule = uni.requireNativePlugin('blood-oxygen')
	
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {

		},
		methods: {
			permissionTest(){
				const res = bloodModule.requestPermission()
				console.log('执行权限 : ...', res)
			},
			
			isEnableBlueBooth(){
				bloodModule.isEnableBlueBooth(res => {
					console.log('蓝牙是否打开 : ...', res, ', type : ', typeof(res))
				})
			},
			
			createTest(){
				console.log("创建 : ", bloodModule.create())
			},
			
			searchDevice(){
				bloodModule.searchDevice("PC-68B", this.waveDataCallback, this.oxygenParamCallback, this.findDevice)
			},
			
			searchFxDevice(){
				bloodModule.searchFXDevice("YGXJ hx-10B", this.waveDataCallback, this.findDevice)
			},
			
			connectFxDevice(){
				bloodModule.connectFxDevice('00006532-0000-1000-8000-00805f9b34fb', '00000438-0000-1000-8000-00805f9b34fb', '00000438-0000-1000-8000-00805f9b34fb', res => {
					console.log("连接结果 : ", res)
				})
			},
			
			// 波形数据回调
			waveDataCallback(data) {
				console.log('波形数据 : ', data)
			},
			// 血氧数据回调
			oxygenParamCallback(data) {
				console.log('血氧数据 : ', data)
			},
			// 查询设备回调
			findDevice(data) {
				console.log('找到设备 : ', data)
			},
			// 连接设备
			connectDevice(){
				console.log('连接设备 : ')
				bloodModule.connectDevice('0000FFB0-0000-1000-8000-00805f9b34fb', '0000FFB2-0000-1000-8000-00805f9b34fb',
				'0000FFB2-0000-1000-8000-00805f9b34fb', res => {
					console.log("连接结果 : ", res)
				})
			},
			// 打开波形数据回调
			openWaveFormCallback(){
				bloodModule.openWaveFormCallback(res => {
					console.log('打开波形数据结果 : ', res)
				})
			},
			
			closeWaveFormCallback(){
				bloodModule.closeWaveFormCallback(res => {
					console.log('关闭波形数据结果 : ', res)
				})
			},
			openListenBloodOxygenParam(){
				bloodModule.openListenBloodOxygenParam(res => {
					console.log('打开血氧参数结果 : ', res)
				})
			},
			closeListenBloodOxygenParam(){
				bloodModule.closeListenBloodOxygenParam(res => {
					console.log('关闭血氧参数结果 : ', res)
				})
			},
			
			testMethod(){
				bloodModule.testMethod(this.findDevice)
			},
			
			alertTest(){
				uni.showToast({
								title: '只有文字弹窗',
								icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
								duration: 2000    //持续时间为 2秒
							})  
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
